package tests;

import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import services.VilainService;
import utils.PowerVilain;
import utils.TypeVilain;
import contracts.ContractException;

public abstract class AbstractVilainTest {
	private VilainService vilain;
	
	protected AbstractVilainTest(){
		this.vilain = null;
	}
	
	
	protected final VilainService getVilain(){
		return this.vilain;
	}
	
	protected final void setVilain(VilainService vilain){
		this.vilain = vilain;
	}
	
	@Before
	public abstract void beforeTests(); 


	@After
	public final void afterTests() {
		this.vilain = null;
	}

	/**
	 * Test de l'objectif 1
	 * postcondition de init : getX(init(typevilain)) = 1
	 * cas de test 1.1 : getX(init(typevilain))=1
	 */
	@Test
	public void testGetX1(){
		try{
			//condition initiale
			this.vilain.init(TypeVilain.BALLONORANGE);
			//operation
			assertTrue(this.vilain.getX() == 1);
		}catch(ContractException e){
			e.printStackTrace();
			Assert.fail("Exception levee sur postcond de init invalide");
		}
	}
	

	/**
	 * Test de l'objectif 1
	 * postcondition de init : getX(init(typevilain)) = 1
	 * cas de test 1.2 : getX(init(typevilain)) != 1
	 * NON VERIFIABLE
	 */
	
	/**
	 * Test de l'objectif 2
	 * postcondition de init : getY(init(typevilain)) = 1
	 * cas de test 1.1 : getY(init(typevilain))=1
	 */
	@Test
	public void testGetY1(){
		try{
			//condition initiale
			this.vilain.init(TypeVilain.BALLONORANGE);
			//operation
			assertTrue(this.vilain.getY() == 1);
		}catch(ContractException e){
			e.printStackTrace();
			Assert.fail("Exception levee sur postcond de init invalide");
		}
	}
	
	/**
	 * Test de l'objectif 2
	 * postcondition de init : getY(init(typevilain)) = 1
	 * cas de test 1.2 : getY(init(typevilain))!=1
	 */
	
	
	/**
	 * Test de l'objectif 3
	 * postcondition de init : getType(init(typevilain)) = typevilain
	 * cas de test 3.1 : getType(init(typevilain)) = typevilain
	 */
	@Test
	public void testGetType1(){
		try{
			//condition initiale
			this.vilain.init(TypeVilain.FANTOMEBLEU);
			//operation
			assertTrue(this.vilain.getType().equals(TypeVilain.FANTOMEBLEU));
		}catch(ContractException e){
			e.printStackTrace();
			Assert.fail("Exception levee sur postcond de init invalide");
		}
	}
	
	/**
	 * Test de l'objectif 3
	 * postcondition de init : getType(init(typevilain)) = typevilain
	 * cas de test 3.2 : getType(init(typevilain)) != typevilain
	 * NON VERIFIABLE
	 */
	
	/**
	 * Test de l'objectif 4
	 * postcondition de init : 	if getType(init(typevilain)) = FANTOMEBLEU 
								then getPower(init(typevilain)) = FANTOMEBLEU	
	 * cas de test 4.1 :		if getType(init(typevilain)) = FANTOMEBLEU 
								then getPower(init(typevilain)) = FANTOMEBLEU
	 */
	@Test
	public void testGetPower1(){
		try{
			//condition initiale
			this.vilain.init(TypeVilain.FANTOMEBLEU);
			//operation
			assertTrue(this.vilain.getPower().equals(PowerVilain.FANTOMEBLEU));
		}catch(ContractException e){
			e.printStackTrace();
			Assert.fail("Exception levee sur postcond de init invalide");
		}
	}
	
	/**
	 * Test de l'objectif 4
	 * postcondition de init : 	if getType(init(typevilain)) = FANTOMEBLEU 
								then getPower(init(typevilain)) = FANTOMEBLEU	
	 * cas de test 4.2 :		if getType(init(typevilain)) = FANTOMEBLEU 
								then getPower(init(typevilain)) != FANTOMEBLEU
	 * NON VERIFIABLE
	 */
	
	
	/**
	 * Test de l'objectif 5
	 * postcondition de init : 	if getType(init(typevilain)) = BALLONORANGE 
								then getPower(init(typevilain)) = BALLONORANGE	
	 * cas de test 5.1:		if getType(init(typevilain)) = BALLONORANGE 
								then getPower(init(typevilain)) = BALLONORANGE
	 */
	@Test
	public void testGetPower2(){
		try{
			//condition initiale
			this.vilain.init(TypeVilain.BALLONORANGE);
			//operation
			assertTrue(this.vilain.getPower().equals(PowerVilain.BALLONORANGE));
		}catch(ContractException e){
			e.printStackTrace();
			Assert.fail("Exception levee sur postcond de init invalide");
		}
	}
	
	/**
	 * Test de l'objectif 5
	 * postcondition de init : 	if getType(init(typevilain)) = BALLONORANGE 
								then getPower(init(typevilain)) = BALLONORANGE	
	 * cas de test 5.2:		if getType(init(typevilain)) = BALLONORANGE 
								then getPower(init(typevilain)) != BALLONORANGE
	 * NON VERIFIABLE								
	 */
}
